﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 静态构造函数
{
    class Program
    {
        static void Main(string[] args)
        {
            SingleTon s1 = SingleTon.Getinstance();
            SingleTon s2 = SingleTon.Getinstance();
            if(s1==s2)
                Console.WriteLine("single类实例s1和s2是相同的");
            Console.ReadKey();
        }
    }
    class SingleTon
    {
        private static SingleTon _instance;
        private SingleTon()
        {
            Console.WriteLine("创建单例对象");
        }
        public static SingleTon Getinstance()
        {
            if (_instance == null)
            {
                _instance = new SingleTon();
            }
            
            {
                return _instance;
            }
        }
    }
}
